<?php
/**
 * (exporter)
 */
namespace App\Exporter\Reimburse;

use App\Models\Reimburse\ReimburseApply;
use App\Models\Reimburse\ReimburseDetail;
use App\Util\User;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
class DetailExporter extends ExcelExporter implements WithMapping
{
    protected $fileName = '返款明细.csv';

    protected $headings =  ['付款状态','核算月','费用类型','刷单类型','订单号/费用描述','提报单号','国家','销售员',
        '亚马逊SKU','公司SKU','产品名称','品类','支付方式','支付账号','币种','支付汇率','订单联系人','备注',
        '佣金币种','佣金支付汇率','佣金支付方式','佣金账号','一次性返款','首次返款','二次返款','支付返款RMB','付款时间',
        '佣金','支付佣金RMB','佣金付款时间','合计支付RMB','收款汇率','收款货币','收款（原币）','收款RMB','配送方式','采购成本','运费','刷单费用RMB'];

    public function map($model) : array
    {
        $paid_amount_rmb = numberFormat($model->rate_odds * ($model->paid_amount_1 + $model->paid_amount_2 + $model->paid_amount_3));
        $paid_amount_rmb_4 = numberFormat($model->rate_odds_4 * $model->paid_amount_4);
        return [
            ReimburseApply::$_paidStatus[$model->paid_status],
            $model->report_date,
            ReimburseApply::$_feeType[$model->fee_type],
            ReimburseApply::$_rType[$model->r_type],
            $model->order_no,
            $model->reimburse_no,
            $model->country->country ?? '',
            User::getUsernameById($model->seller_id),
            $model->seller_sku ?: '',
            $model->sku->psku_code ?? '',
            $model->sku->psku_cn ?? '',
            $model->skuClassify->title ?? '',
            ReimburseApply::$_paidMethod[$model->paid_method],
            $model->paid_account_no,
            $model->currency_code,
            $model->rate_odds,
            $model->order_atten,
            $model->remarks ,
            $model->currency_code_4,
            $model->rate_odds_4,
            $model->paid_method_4 ? ReimburseApply::$_paidMethod[$model->paid_method_4] : '',
            $model->paid_account_no_4,
            $model->paid_amount_1,
            $model->paid_amount_2,
            $model->paid_amount_3,
            $paid_amount_rmb,
            $model->paid_date,
            $model->paid_amount_4,
            $paid_amount_rmb_4,
            $model->paid_date_4,
            numberFormat($paid_amount_rmb + $paid_amount_rmb_4),
            $model->r_rate_odds,
            $model->r_currency_code,
            $model->r_amount,
            $model->r_amount_rmb,
            $model->fulfillment_type ? ReimburseDetail::$_fulfillmentType[$model->fulfillment_type] : '',
            $model->purchase_price_rmb,
            $model->shipment_price_rmb,
            $model->amount_rmb,
        ];
    }
}
